package 设计模式.创建者模式.建造者模式;

/**
 * @Author: kirito
 * @Date: 2024/3/10 18:26
 * @Description: TODO
 */

public class Car {
    private String name;
    private Integer price;

    public void setName(String name) {
        this.name = name;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}

abstract class CarBuilder{
    protected Car car = new Car();
    public abstract void buildName();
    public abstract void buildPrice();
    public abstract Car getCar();
}

class DWBuilder extends CarBuilder {

    @Override
    public void buildName() {
        car.setName("大众");
    }

    @Override
    public void buildPrice() {
        car.setPrice(100);
    }

    @Override
    public Car getCar() {
        return car;
    }

}
class Director_2{
    private CarBuilder carBuilder;

    public Director_2(CarBuilder carBuilder) {
        this.carBuilder = carBuilder;
    }

    public Car construct() {
        carBuilder.buildName();
        carBuilder.buildPrice();
        return carBuilder.getCar();
    }
}

class Client_1 {
    public static void main(String[] args) {
        Director_2 director_2 = new Director_2(new DWBuilder());
        Car dw = director_2.construct();
        System.out.println(dw.toString());
    }
}
